﻿//-----------------------------------------------------------------------
// <copyright file="ComponentLoggerTests.cs" author="Artak Mkrtchyan">
//     Creative Commons - GNU General Public License (http://creativecommons.org/licenses/GPL/2.0/
// </copyright>
// <author>Artak Mkrtchyan</author>
// <email>mkArtak@gmail.com</email>
// <date>09 Jun 2013</date>
//-----------------------------------------------------------------------

using ConsoleHoster.Common.Utilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using System;
using TestUtilities;

namespace ConsoleHoster.Common.UnitTests.UtilitiesTests
{
	[TestClass]
	public class ComponentLoggerTests
	{
		private const string componentName = "any component name";
		private const string messageToLog = "any message with patther";

		private ComponentLogger logger;
		private Mock<ILogger> mockLogger;

		[TestInitialize]
		public void Initialize()
		{
			this.mockLogger = new Mock<ILogger>();
			this.logger = new ComponentLogger(componentName, this.mockLogger.Object);
		}

		[ExpectedException(typeof(ArgumentException))]
		[TestMethod]
		public void Constructor_ThrowsOnNullComponentName()
		{
			new ComponentLogger(null, this.mockLogger.Object);
		}

		[ExpectedException(typeof(ArgumentException))]
		[TestMethod]
		public void Constructor_ThrowsOnEmptyComponentName()
		{
			new ComponentLogger("   ", this.mockLogger.Object);
		}

		[TestMethod]
		public void LogMessage_DecoratesMessageWithComponentName()
		{
			this.logger.LogMessage(messageToLog);

			this.mockLogger.Verify(l => l.LogMessage(ComponentLogger.DecoratedMessagePattern, componentName, messageToLog), Times.Once());
		}

		[TestMethod]
		public void LogError_DecoratesMessageWithComponentName()
		{
			this.logger.LogError(messageToLog);

			this.mockLogger.Verify(l => l.LogError(ComponentLogger.DecoratedMessagePattern, componentName, messageToLog), Times.Once());
		}

		[TestMethod]
		public void LogWarning_DecoratesMessageWithComponentName()
		{
			this.logger.LogWarning(messageToLog);

			this.mockLogger.Verify(l => l.LogWarning(ComponentLogger.DecoratedMessagePattern, componentName, messageToLog), Times.Once());
		}

		[TestMethod]
		public void Dispose_DisposesUnderlyingLogger()
		{
			this.logger.Dispose();

			this.mockLogger.Verify(l => l.Dispose(), Times.Once());
		}
	}
}
